<template>
  <div class="app-container">
    <!-- 高级查询 -->
    <el-form v-show="searchVisible" ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item label=":">
        <el-input v-model="queryParams.wid" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.customerNo" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.materialNo" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.warehouseCode" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.feeUnitPrice" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.feeUnitCode" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.warehouseUnitCode" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.convertQuantity" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.startQuantity" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.endQuantity" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.feeSubjectCode" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-date-picker v-model="queryParams.startDate" type="date" value-format="yyyy-MM-dd" size="small" placeholder="选择" clearable />
      </el-form-item>
      <el-form-item label=":">
        <el-date-picker v-model="queryParams.endDate" type="date" value-format="yyyy-MM-dd" size="small" placeholder="选择" clearable />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.siteCode" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.creater" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-date-picker v-model="queryParams.createDate" type="date" value-format="yyyy-MM-dd" size="small" placeholder="选择" clearable />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.version" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.warehouseArea" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.warehouseSumFee" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.productFamily" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.productCode" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="更新时间:">
        <el-date-picker v-model="queryParams.updateDate" type="date" value-format="yyyy-MM-dd" size="small" placeholder="选择更新时间" clearable />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button v-hasPermission="['pms:tWhWarehouseFeeUnit:insert']" type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['pms:tWhWarehouseFeeUnit:update']" type="success" icon="el-icon-edit" size="mini" :disabled="isSingle" @click="handleEdit">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['pms:tWhWarehouseFeeUnit:delete']" type="danger" icon="el-icon-delete" size="mini" :disabled="isMultiple" @click="handleRemove">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['pms:tWhWarehouseFeeUnit:export']" type="warning" icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar :show-search.sync="searchVisible" @queryTable="handleQuery" />
    </el-row>

    <!-- 数据列表 -->
    <el-table v-loading="loading" :data="page.records" highlight-current-row @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="" align="center" prop="wid" />
      <el-table-column label="" align="center" prop="customerNo" />
      <el-table-column label="" align="center" prop="materialNo" />
      <el-table-column label="" align="center" prop="warehouseCode" />
      <el-table-column label="" align="center" prop="feeUnitPrice" />
      <el-table-column label="" align="center" prop="feeUnitCode" />
      <el-table-column label="" align="center" prop="warehouseUnitCode" />
      <el-table-column label="" align="center" prop="convertQuantity" />
      <el-table-column label="" align="center" prop="startQuantity" />
      <el-table-column label="" align="center" prop="endQuantity" />
      <el-table-column label="" align="center" prop="feeSubjectCode" />
      <el-table-column label="" align="center" prop="startDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="" align="center" prop="endDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="" align="center" prop="siteCode" />
      <el-table-column label="" align="center" prop="creater" />
      <el-table-column label="" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="" align="center" prop="version" />
      <el-table-column label="" align="center" prop="warehouseArea" />
      <el-table-column label="" align="center" prop="warehouseSumFee" />
      <el-table-column label="" align="center" prop="productFamily" />
      <el-table-column label="" align="center" prop="productCode" />
      <el-table-column label="" align="center" prop="productType" />
      <el-table-column label="" align="center" prop="feeType" />
      <el-table-column label="记录 ID，系统自动产生" align="center" prop="id" />
      <el-table-column label="更新时间" align="center" prop="updateDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-hasPermission="['pms:tWhWarehouseFeeUnit:update']" size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)">修改</el-button>
          <el-button v-hasPermission="['pms:tWhWarehouseFeeUnit:delete']" size="mini" type="text" icon="el-icon-delete" @click="handleRemove(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <pagination v-show="page.total>0" :total="page.total" :page.sync="page.current" :limit.sync="page.pageSize" @pagination="handleQuery" />

    <!-- 添加/修改对话框 -->
    <el-dialog :title="tWhWarehouseFeeUnitFormDialog.title" :visible.sync="tWhWarehouseFeeUnitFormDialog.visible" :close-on-click-modal="false" :before-close="resetTWhWarehouseFeeUnitFormDialog" width="500px" append-to-body>
      <el-form ref="tWhWarehouseFeeUnitForm" :model="tWhWarehouseFeeUnitFormData" :rules="tWhWarehouseFeeUnitFormRules" label-width="80px">
        <el-form-item label="" prop="wid">
          <el-input v-model="tWhWarehouseFeeUnitFormData.wid" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="customerNo">
          <el-input v-model="tWhWarehouseFeeUnitFormData.customerNo" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="materialNo">
          <el-input v-model="tWhWarehouseFeeUnitFormData.materialNo" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="warehouseCode">
          <el-input v-model="tWhWarehouseFeeUnitFormData.warehouseCode" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="feeUnitPrice">
          <el-input v-model="tWhWarehouseFeeUnitFormData.feeUnitPrice" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="feeUnitCode">
          <el-input v-model="tWhWarehouseFeeUnitFormData.feeUnitCode" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="warehouseUnitCode">
          <el-input v-model="tWhWarehouseFeeUnitFormData.warehouseUnitCode" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="convertQuantity">
          <el-input v-model="tWhWarehouseFeeUnitFormData.convertQuantity" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="startQuantity">
          <el-input v-model="tWhWarehouseFeeUnitFormData.startQuantity" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="endQuantity">
          <el-input v-model="tWhWarehouseFeeUnitFormData.endQuantity" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="feeSubjectCode">
          <el-input v-model="tWhWarehouseFeeUnitFormData.feeSubjectCode" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="startDate">
          <el-date-picker v-model="tWhWarehouseFeeUnitFormData.startDate" type="date" value-format="yyyy-MM-dd" size="small" style="width: 100%" placeholder="选择" clearable />
        </el-form-item>
        <el-form-item label="" prop="endDate">
          <el-date-picker v-model="tWhWarehouseFeeUnitFormData.endDate" type="date" value-format="yyyy-MM-dd" size="small" style="width: 100%" placeholder="选择" clearable />
        </el-form-item>
        <el-form-item label="" prop="siteCode">
          <el-input v-model="tWhWarehouseFeeUnitFormData.siteCode" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="creater">
          <el-input v-model="tWhWarehouseFeeUnitFormData.creater" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="createDate">
          <el-date-picker v-model="tWhWarehouseFeeUnitFormData.createDate" type="date" value-format="yyyy-MM-dd" size="small" style="width: 100%" placeholder="选择" clearable />
        </el-form-item>
        <el-form-item label="" prop="version">
          <el-input v-model="tWhWarehouseFeeUnitFormData.version" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="warehouseArea">
          <el-input v-model="tWhWarehouseFeeUnitFormData.warehouseArea" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="warehouseSumFee">
          <el-input v-model="tWhWarehouseFeeUnitFormData.warehouseSumFee" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="productFamily">
          <el-input v-model="tWhWarehouseFeeUnitFormData.productFamily" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="productCode">
          <el-input v-model="tWhWarehouseFeeUnitFormData.productCode" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="更新时间" prop="updateDate">
          <el-date-picker v-model="tWhWarehouseFeeUnitFormData.updateDate" type="date" value-format="yyyy-MM-dd" size="small" style="width: 100%" placeholder="选择更新时间" clearable />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmTWhWarehouseFeeUnitFormDialog">确 定</el-button>
        <el-button @click="resetTWhWarehouseFeeUnitFormDialog">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import TWhWarehouseFeeUnitApi from '@/api/pms/TWhWarehouseFeeUnitApi'

const defaultTWhWarehouseFeeUnitFormData = {
  wid: null,
  customerNo: null,
  materialNo: null,
  warehouseCode: null,
  feeUnitPrice: null,
  feeUnitCode: null,
  warehouseUnitCode: null,
  convertQuantity: null,
  startQuantity: null,
  endQuantity: null,
  feeSubjectCode: null,
  startDate: null,
  endDate: null,
  siteCode: null,
  creater: null,
  createDate: null,
  version: null,
  warehouseArea: null,
  warehouseSumFee: null,
  productFamily: null,
  productCode: null,
  productType: null,
  feeType: null,
  updateDate: null

}
export default {
  name: 'TWhWarehouseFeeUnitList',
  data() {
    return {
      options: {
        sysYnTypeOptions: this.$constant.sysYnTypeOptions
      },
      queryParams: {
        wid: null,
        customerNo: null,
        materialNo: null,
        warehouseCode: null,
        feeUnitPrice: null,
        feeUnitCode: null,
        warehouseUnitCode: null,
        convertQuantity: null,
        startQuantity: null,
        endQuantity: null,
        feeSubjectCode: null,
        startDate: null,
        endDate: null,
        siteCode: null,
        creater: null,
        createDate: null,
        version: null,
        warehouseArea: null,
        warehouseSumFee: null,
        productFamily: null,
        productCode: null,
        productType: null,
        feeType: null,
        updateDate: null,
        isValid: this.$constant.Y
      },
      page: {
        current: 1,
        pageSize: 10,
        total: 0,
        records: []
      },
      tWhWarehouseFeeUnitFormDialog: {
        title: '',
        visible: false
      },
      tWhWarehouseFeeUnitFormData: Object.assign({}, defaultTWhWarehouseFeeUnitFormData),
      tWhWarehouseFeeUnitFormRules: {
        wid: [{ required: true, message: '不能为空', trigger: 'blur' }],

        siteCode: [{ required: true, message: '不能为空', trigger: 'blur' }],

        creater: [{ required: true, message: '不能为空', trigger: 'blur' }],

        createDate: [{ required: true, message: '不能为空', trigger: 'blur' }],

        version: [{ required: true, message: '不能为空', trigger: 'blur' }],

        updateDate: [{ required: true, message: '更新时间不能为空', trigger: 'blur' }]

      },
      loading: true,
      searchVisible: true,
      multipleSelection: [],
      isSingle: true,
      isMultiple: true
    }
  },
  created() {
    this.handleQuery()
    this.loadOptions()
  },
  methods: {
    loadOptions() {
    },
    handleAdd() {
      this.openTWhWarehouseFeeUnitFormDialog()
    },
    handleRemove(row) {
      const ids = row.id || this.multipleSelection.map(item => item.id)
      this.$confirm('是否确认删除数据?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return TWhWarehouseFeeUnitApi.remove(ids)
      }).then(() => {
        this.handleQuery()
        this.$message.success('删除成功')
      })
    },
    handleEdit(row) {
      const id = row.id || this.multipleSelection.map(item => item.id)[0]
      this.openTWhWarehouseFeeUnitFormDialog(id)
    },
    handleQuery() {
      this.loading = true
      TWhWarehouseFeeUnitApi.page(this.queryParams, this.page).then(response => {
        this.page.records = response.data.records
        this.page.total = response.data.total
        this.loading = false
      }, () => {
        this.loading = false
      })
    },
    handleExport() {
      this.$confirm('是否确认导出数据?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return TWhWarehouseFeeUnitApi.exportData(this.queryParams)
      }).then(response => {
        this.$common.download(response.msg)
      })
    },
    openTWhWarehouseFeeUnitFormDialog(id) {
      this.tWhWarehouseFeeUnitFormDialog.visible = true
      if (id) {
        this.tWhWarehouseFeeUnitFormDialog.title = '共享仓储缴费单位-修改'
        TWhWarehouseFeeUnitApi.get(id).then(response => {
          this.tWhWarehouseFeeUnitFormData = {
            ...this.tWhWarehouseFeeUnitFormData,
            ...response.data
          }
        })
      } else {
        this.tWhWarehouseFeeUnitFormDialog.title = '共享仓储缴费单位-添加'
      }
    },
    confirmTWhWarehouseFeeUnitFormDialog() {
      this.$refs['tWhWarehouseFeeUnitForm'].validate(valid => {
        if (valid) {
          if (this.tWhWarehouseFeeUnitFormData.id) {
            TWhWarehouseFeeUnitApi.edit(this.tWhWarehouseFeeUnitFormData).then(response => {
              this.$message.success('修改成功')
              this.resetTWhWarehouseFeeUnitFormDialog()
              this.handleQuery()
            })
          } else {
            TWhWarehouseFeeUnitApi.add(this.tWhWarehouseFeeUnitFormData).then(response => {
              this.$message.success('添加成功')
              this.resetTWhWarehouseFeeUnitFormDialog()
              this.handleQuery()
            })
          }
        }
      })
    },
    resetTWhWarehouseFeeUnitFormDialog() {
      this.tWhWarehouseFeeUnitFormDialog = {
        title: '',
        visible: false
      }
      this.tWhWarehouseFeeUnitFormData = Object.assign({}, defaultTWhWarehouseFeeUnitFormData)
      this.resetForm('tWhWarehouseFeeUnitForm')
    },
    handleSelectionChange(selection) {
      this.multipleSelection = selection
      this.isSingle = selection.length !== 1
      this.isMultiple = !selection.length
    },
    resetQuery() {
      this.page.current = 1
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>
